const Mock = require('mockjs')
const getQuestionList = require('./data/getQuestionList')
const getComponentList = require('./data/getComponentList')


const Random = Mock.Random

module.exports = [
    // 获取问卷
    {
        url: '/api/question/:id',
        method: 'get',
        response() {
            return {
                errno: 0,
                data: {
                    _id: Random.id(),
                    title: Random.ctitle(),
                    desc: '问卷描述',
                    js: '',
                    css: '',
                    isPublished: true,
                    isStar: false,
                    isDeleted: false,
                    // 组件列表
                    componentList: getComponentList()
                }
            }
        }
    },
    // 新建问卷
    {
        url: '/api/question',
        method: 'post',
        response() {
            return {
                errno: 0,
                data: {
                    _id: Random.id(),
                    title: Random.ctitle(),
                }
            }
        }
    },
    // 获取问卷列表
    {
        url: '/api/question',
        method: 'get',
        response(ctx) {
            const isDeleted = ctx.query.isDeleted
            const isStar = ctx.query.isStar
            const page = parseInt(ctx.query.page) || 1
            const pageSize = parseInt(ctx.query.pageSize) || 10


            return {
                errno: 0,
                data: {
                    list: getQuestionList({ len: pageSize, isDeleted, isStar }),
                    total: 100
                }
            }
        }
    },
    // 更新问卷
    {
        url: '/api/question/:id',
        method: 'patch',
        response() {
            return {
                errno: 0
            }
        }
    },
    // 复制问卷
    {
        url: '/api/question/duplicate/:id',
        method: 'post',
        response() {
            return {
                errno: 0,
                data: {
                    _id: Random.id()
                }
            }
        }
    },
    // 批量彻底删除
    {
        url: '/api/question',
        method: 'delete',
        response() {
            return {
                errno: 0
            }
        }
    }
]